Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
Axios getPosts error: Unexpected token, expected "," (25:4)

I am trying to get an axios getPosts to work. I am getting a syntax error but I can't find what's wrong with my code.

getPosts = async () => {
    let data = await api.get('/').then(({ data })
    => data);
    this.setState({ posts: data })
  }

The error is posted below:

./src/App.js
SyntaxError: /home/roxx/Documents/eternal_kings_web_app/Twitter-Clone/src/App.js: Unexpected token, expected "," (25:4)

  23 |   getPosts = async () => {
  24 |     let data = await api.get('/').then(({ data })
> 25 |     => data);
     |     ^
  26 |     this.setState({ posts: data })
  27 |   }

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The source of your syntax error is the newline in your arrow function.

Per MDN on Arrow Functions: "Multiline statements require body braces and return." To stick with the one-line:

let data = await api.get("/").then(({ data }) => data);

And to include the desired setState:

let data = await api.get("/").then(({ data }) => this.setState({ posts: data }));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda